package com.xx.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xx.entity.Employees;
import com.xx.service.IEmployeesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author AY
 * @since 2024-12-09 10:49
 */
@RestController
@RequestMapping("/employees")
public class EmployeesController {
    @Autowired
    IEmployeesService iEmployeesService;

    // 添加员工
    @PostMapping
    public boolean save(@RequestBody Employees employees) {
        return iEmployeesService.save(employees);
    }

    // 通过ID删除员工
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Integer id) {
        return iEmployeesService.removeById(id);
    }

    // 修改
    @PutMapping("/{id}")
    public boolean update(@PathVariable Integer id, @RequestBody Employees employees) {
        employees.setEmployeeId(id);
        return iEmployeesService.updateById(employees);
    }

    // 通过ID查询员工信息
    @GetMapping("/{id}")
    public Employees getById(@PathVariable Integer id) {
        return iEmployeesService.getById(id);
    }

    // 分页查询
    @GetMapping("/page")
    public Page<Employees> page(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "3") Integer size) {
        Page<Employees> page = new Page<>(current, size);
        return iEmployeesService.page(page);
    }
}